<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>入/出库明细</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="description" content="入/出库明细">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<jsp:include page="../commons/top.jsp"/>

	<script type='text/javascript' src='/sm/dwr/interface/managerAjax.js'></script>
    <script type='text/javascript' src='/sm/dwr/engine.js'></script>
	<script type='text/javascript' >
	function del(id,productId,number){
	      if(window.confirm("确定删除？")){
              var form = document.getElementById("listForm");
              form.id.value = id;
              form.number.value = number;
              form.productId.value = productId;
              form.action = "/sm/controller/itemManager/del";
              form.submit();
          }
      }
      
      function changeProduct(typeItemId){
          managerAjax.getProductList(typeItemId,callBack);
      }
      
      function callBack(productList){
          var product = document.getElementById("product");
          product.length = 0;
          if(productList!=null && productList.length>0){
              for(var i=0;i<productList.length;i++){
                   product.options[i] = new Option(productList[i].name+" 当前数量："+productList[i].currentTotalNumber,productList[i].id);
              }
          }
      }
      
      function add(){
          var form = document.getElementById("addForm");
          
          if(isNull(form.typeItemId.value)){
             alert("请选择产品分类！");
             return false;
          }
          
          if(isNull(form.productId.value)){
             alert("请选择产品名称！");
             return false;
          }
          if(!isNumber(form.number.value)){
             alert("数量只能为数字！");
             return false;
          }

          if(form.operation.value == "out"){
              form.number.value = "-"+form.number.value;
          }
          form.submit();
      }
      
      function changePage(pageNo){
          var form = document.getElementById("pageForm");
          form.currentPage.value = pageNo;
          form.submit();
      }
      
      function uploadExcel(){
          window.open ('/sm/controller/itemManager/preUpload.html', 'newwindow', 'height=400, width=400, top=200, left=500, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
      }

	</script>

  </head>

  <body>
   <form id="pageForm" action="/sm/controller/itemManager/list" method="POST">
  <table><tr><td>查询</td></tr></table>
  <table>
      <input type="hidden" name="currentPage" value=""/>
  <table>
  <tr>
  <td>产品名称</td><td><input type="text" name="product.name" value=""></td>
  <td>操作</td>
  <td><select name="operation">
           <option value="">全部</option>
           <option value="in">入库</option>
           <option value="out">出库</option>   
      </select></td>
  <td><input type="button" value="查询" onclick="changePage(1);"></td>
  </tr>
  </table>
  </form>
  <form id="listForm" action="/sm/controller/itemManager/del" method="POST">
  <input type="hidden" name="id" value=""/>
  <input type="hidden" name="number" value=""/>
  <input type="hidden" name="productId" value=""/>
  <table>
  <tr><td>出/入库明细列表</td>
  <c:if test="${sessionScope.user.role == 'admin' || sessionScope.user.role == 'opera'}"><td><input type="button" value="导入excel" onclick="uploadExcel();"/></td></c:if></tr></table>
   <table>
  <tr>
      <td>序号</td>
      <td>操作</td>
      <td>产品分类</td>
      <td>产品名称</td>
      <td>数量</td>
      <td>状态</td>
      <td>操作时间</td>
      <td>项目名称</td>
      
      <td>操作人</td>
      <td>备注</td>
      <td>数据操作</td>

  </tr>
    <c:if test="${itemManagerList!=null}">
       <c:forEach var="itemManager" items="${itemManagerList}">
          <tr>
              <td>${itemManager.id}&nbsp;</td>
              <td><c:if test="${itemManager.operation == 'in'}"><font color="red">入库</font></c:if>
              <c:if test="${itemManager.operation == 'out'}"><font color="blue">出库</font></c:if>
              &nbsp;
              </td>
              <td><c:forEach var="typeItem" items="${typeItemList}">
                    <c:if test="${typeItem.id==itemManager.typeItemId}">${typeItem.displayName}</c:if>
                </c:forEach>&nbsp;</td>
              <td>${itemManager.product.name}&nbsp;</td>
              <td>${itemManager.number}&nbsp;</td>
              <td><c:if test="${itemManager.stat == 0}"><font color="red">无效</font></c:if>
              <c:if test="${itemManager.stat == 1}"><font color="blue">有效</font></c:if>
              &nbsp;
              </td>
              <td><fmt:formatDate value="${itemManager.statTime}"  pattern= "yyyy-MM-dd H:mm:ss" /> &nbsp;</td>
              <td>${itemManager.project}&nbsp;</td>
              <td>${itemManager.staff}&nbsp;</td>
              <td>${itemManager.note}&nbsp;</td>
              
              <td><c:if test="${itemManager.stat == 1}"><c:if test="${sessionScope.user.role == 'admin' || sessionScope.user.role == 'opera'}"><input type="button" value="删除" onclick="del(${itemManager.id},${itemManager.productId},${itemManager.number});"/></c:if></c:if>&nbsp;</td>
          </tr>
          
       </c:forEach>
    </c:if>
    </table>
    </form>
    <jsp:include page="../commons/page.jsp"/>
    <c:if test="${sessionScope.user.role == 'admin' || sessionScope.user.role == 'opera'}">
    <form id="addForm" action="/sm/controller/itemManager/add" method="POST">
    <table>
    <tr><td>添加出/入库明细</td></tr>
        <tr>
            <td>
                                          操作：
            </td>
            <td>
            <select name="operation">
                   <option value="in">入库</option>
                   <option value="out">出库</option>
              </select></td>
              </tr>
        <tr>
            <td>产品分类：</td>
            <td><select name="typeItemId" id="typeItem" onchange="changeProduct(this.value);">
                <c:forEach var="typeItem" items="${typeItemList}">
                    <option value="${typeItem.id}">${typeItem.displayName}</option>
                </c:forEach>
                </select></td>
                </tr>
        <tr>
            <td>产品名称：</td>
            <td><select name="productId" id="product" maxlength="100">
                     
            </select></td>
</tr>
        <tr>
            <td>数量：</td>
            <td><input type="text" name="number" value="0" maxlength="10"/></td>
        </tr>
        <tr>
            <td>项目名称：</td>
            <td><input type="text" name="project" value="" maxlength="100"></td>
</tr>
        <tr>
            <td>操作人：</td>
            <td><input type="text" name="staff" value="" maxlength="50"/></td>
</tr>
        <tr>
            <td>备注：</td>
            <td><textarea name="note" rows="5" cols="20" wrap="soft"></textarea></td>
        </tr>
        <tr>
            <td>&nbsp;<input type="hidden" name="stat" value="1"/></td><td><input type="button" value="提交" onclick="add();"/></td></tr>
            
    </table>
    </form>
    </c:if>
    
  </body>
      <script type='text/javascript'>
        changeProduct(document.getElementById("typeItem").value);
    </script> 
</html>
